interface ObjectAny {
  [key: string]: any;
}

let obj1: ObjectAny = {
  name: "1",
  age: 2,
  married: true,
};
console.log(obj1);
console.log(obj1["name"]);
console.log(obj1.married);

interface MyArray<T> {
  [key: number]: T;
}

let arr: MyArray<number> = [12, 34, 45, 56];
console.log(arr);

let arr2: MyArray<string> = ["a", "b", "c", "d"];
console.log(arr2);

//映射类型
type PropKeys = "x" | "y" | "z";
type Type = { x: number; y: number; z: number };
type Type2 = { [key in PropKeys]: number }; //简化属性指定类型, 类型必须一致
let v: Type2 = {
  x: 1,
  y: 2,
  z: 3,
};
console.log(v);

type Props = { x: number; y: boolean; z: string };
type PartialProps = Partial<Props>; //类型不一致
let v2: PartialProps = {
  x: 1,
  y: true,
  z: "string",
};
console.log(v2);

//索引查询
type kk = Props["x" | "y"];
